#ifndef CCUSTOMBOXVIEW_H_
#define CCUSTOMBOXVIEW_H_

#include "CommonType.h"

#include <QWidget>
#include <QButtonGroup>
#include <QMutex>
#include <QPushButton>

class CCustomBoxCell : public QPushButton
{
    Q_OBJECT

public:
	CCustomBoxCell(QWidget* parent = 0);
	~CCustomBoxCell();

    inline void SetData(const zl::Locker& locker) { locker_ = locker; update(); }
    inline zl::Locker Data() { return locker_; }
    inline void SetTagNumber(int32_t no) { tag_number_ = no; }

	void show();
	void hide();

protected:
	QString get_locker_no_string(int32_t no);
	QString get_locker_size_string(int32_t size);

	void paintEvent(QPaintEvent* e) override;

private:
	zl::Locker		locker_;
	bool			is_visiable_;
    int32_t tag_number_;
};

class CCustomBoxView : public QWidget
{
	Q_OBJECT

public:
	CCustomBoxView(QWidget* parent = 0);
	~CCustomBoxView();

	inline void Reset() { hide_all(); }
	void SetLayout(const zl::LockerLayout& layout);
    void SetData(const zl::LockerVec& lockers, int32_t tag_number);

protected:
	void init();
	void hide_all();
	void resize_btngroup(int32_t size);

    bool eventFilter(QObject *watched, QEvent *event);
    void mousePressEvent(QMouseEvent* e) override;
    void mouseMoveEvent(QMouseEvent* e) override;
    void mouseReleaseEvent(QMouseEvent* e) override;

signals:
	void boxClicked(int id);

private:
	std::vector<CCustomBoxCell*>	cells_;
    QButtonGroup*					btn_group_;

    bool        flag_drag_;
    bool        flag_drag_continue_;
    int32_t     drag_posx_;
    int32_t     drag_posy_;
};

#endif // CCUSTOMBOXVIEW_H_
